<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div>div</div>
    <p>p</p>
    <div>div</div>
    <span>span</span>
    <p>p</p>
    <div>div</div>
</body>
<script>
    // 选择器封装
    function select( selector ) {
        return document.querySelectorAll( selector );
    }
    // 循环封装
    function each( arr, callback ) {
        for ( var i = 0; i < arr.length; i++ ) {
            callback( arr[ i ], i );
        }
    }
    var nedes = select( 'div, p' );
    each( nedes, function( v ) {
        v.style.border = v.nodeName == 'DIV'
                        ? '1px solid red'
                        : '1px solid blue';
    });
</script>
</html>